package com.moxiao.yfjh.module.blind.controller.app;

import com.moxiao.yfjh.framework.common.pojo.CommonResult;
import com.moxiao.yfjh.module.blind.controller.admin.distributionsharing.vo.DistributionSharingCreateReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.distributionsharing.vo.DistributionSharingRespVO;
import com.moxiao.yfjh.module.blind.convert.distributionsharing.DistributionSharingConvert;
import com.moxiao.yfjh.module.blind.dal.dataobject.distributionsharing.DistributionSharingDO;
import com.moxiao.yfjh.module.blind.service.distributionsharing.DistributionSharingService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.moxiao.yfjh.framework.common.pojo.CommonResult.success;
import static com.moxiao.yfjh.framework.common.util.servlet.ServletUtils.getClientIP;

@Tag(name = "app - 相亲分销分享")
@RestController
@RequestMapping("/blind/distribution/sharing")
@Validated
public class AppDistributionSharingController {

    @Resource
    private DistributionSharingService distributionSharingService;

    @PostMapping("/create")
    @Operation(summary = "创建相亲分销分享")
    public CommonResult<Long> createDistributionSharing(@Valid @RequestBody DistributionSharingCreateReqVO createReqVO) {

        createReqVO.setIp(getClientIP());
        return success(distributionSharingService.createDistributionSharing(createReqVO));
    }

    @GetMapping("/get")
    @Operation(summary = "获得相亲分销分享")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<DistributionSharingRespVO> getDistributionSharing(@RequestParam("id") Long id) {
        DistributionSharingDO distributionSharing = distributionSharingService.getDistributionSharing(id);
        return success(DistributionSharingConvert.INSTANCE.convert(distributionSharing));
    }
}
